/**
 * 销售回款预测 - 编辑页面
 * @author liuw
 * @date 2019/09/02
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        vueData = {
            isAdd: false,
            isDetail:false,
            form: {
                GWAKL003: null,
                GWAKL003_: null,
                GWAGL003:null,
                GWADL004: null,
                GWAOL003: null,
                GWAML003: null,
                GWAML004: null,
                GWABL003: null,
                GWBS010_NAME_: null,
                GWBS018_NAME_: null
            },
            rules: {
                GWBSDOCDATE: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWBSACTI: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWBS005: [
                    { type: 'number', message: '数量必须为数字值'}
                ],
                GWBS006: [
                    { type: 'number', message: '单价必须为数字值'}
                ],
                GWBS007: [
                    { type: 'number', message: '金额必须为数字值'}
                ]
            },
            selectOptions:{
                sys_y_n:app.datas_("sys_y_n")
            },
        },
        callObj
    ;

    var Gwat550Edit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwat550_edit',
                _loadTplsFull: [{
                    dom: 'common_open_window', tpl: 'common/_open_window'
                }
                ]
            }, win);
        },

        editData: function () {
            app.ajax({
                xurl: 'crm/gwat550/edit',
                xdata: vueData.form,
                loading: true,
                okmsg: self._moduleName + '信息修改成功',
                cb: function (result) {
                    if (result.ok) {
                        //同步更新缓存对应的值
                        //callObj.update(result.xdata);
                        app.pageModule('gwat550').reloadTableCurr();
                        self._closeTpl();
                    }
                }
            });
        },

        addData: function () {
            app.ajax({
                xurl: 'crm/gwat550/add',
                xdata: vueData.form,
                loading: true,
                okmsg: self._moduleName + '信息保存成功',
                cb: function (result) {
                    if (result.ok) {
                        app.pageModule('gwat550').reloadTableCurr();
                        self._closeTpl();
                    }
                }
            });
        },

        _call: function (tagData) {
            if(tagData.is_detail){
                vueData.isDetail = true;
            }else {
                vueData.isDetail = false;
            }
            if (tagData.is_add) {
                vueData.isAdd=true;
                app.extendUpLow({
                    target: vueData.form,
                    res: {
                        GWBSACTI:'Y'
                    },
                    reset: true
                });
            } else {
                vueData.isAdd = false;
                callObj = tagData.obj;
                app.extendUpLow({
                    target: vueData.form,
                    res: callObj.data,
                    reset: true
                });
            }
        },
        _ready: function () {
            vueData.form = app.fields_(['GWBS_T'],vueData.form);
            var vue = new Vue({
                el: '#gwat550_edit',
                data: vueData,
                methods: {
                    cancel: function () {
                        self._closeTpl();
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                if (vueData.isAdd) {
                                    self.addData();
                                } else {
                                    self.editData();
                                }
                            }
                        });
                    },
                    openGwbs002:function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_gwak001',
                                    columnList: [
                                        {label: '客户编号', prop: 'GWAK001', width: '150'},
                                        {label: '客户简称', prop: 'GWAKL003', width: '150'},
                                        {label: '客户全称', prop: 'GWAKL004', width: '150'}
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWBS002 = data.GWAK001;
                                    vueData.form.GWAKL003 = data.GWAKL003;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择客户',
                                area: ['600px', '465px']
                            }
                        });
                    },
                    openGwbs009:function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'cq_gwak001_1',
                                    columnList: [
                                        {label: '客户编号', prop: 'GWAK001', width: '150'},
                                        {label: '客户简称', prop: 'GWAKL003', width: '150'},
                                        {label: '客户全称', prop: 'GWAKL004', width: '150'}
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWBS009 = data.GWAK001;
                                    vueData.form.GWAKL003_ = data.GWAKL003;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择经销商信息',
                                area: ['600px', '465px']
                            }
                        });

                    },
                    openGwbs001:function () {
                        if(vueData.form.GWBS002 == null || vueData.form.GWBS002 == ''){
                            app.showMessage("请先选择客户！");
                            return ;
                        }
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_gwbg001',
                                    searchParam: {
                                        GWBG002:vueData.form.GWBS002
                                    },
                                    columnList: [
                                        {label: '商机编号', prop: 'GWBG001', width: '150'},
                                        {label: '说明', prop: 'GWBGL003', width: '150'},
                                        {label: '助记码', prop: 'GWBGL004', width: '150'}
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWBS001 = data.GWBG001;
                                    vueData.form.GWBGL003 = data.GWBGL003;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择商机',
                                area: ['600px', '465px']
                            }
                        });
                    },
                    openGwagl003:function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_gwag001',
                                    columnList: [
                                        {label: '行业编号', prop: 'GWAG001', width: '150'},
                                        {label: '行业名称', prop: 'GWAGL003', width: '150'},
                                        {label: '助记码', prop: 'GWAGL004', width: '150'}
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWBS015 = data.GWAG001;
                                    vueData.form.GWAGL003 = data.GWAGL003+' '+data.GWAG001;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择行业',
                                area: ['600px', '465px']
                            }
                        });
                    },
                    openGwadl003:function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_gwad002',
                                    searchParam: {
                                        GWAD001: "4"
                                    },
                                    columnList: [
                                        {label: '区域编号', prop: 'GWAD002', width: '150'},
                                        {label: '区域名称', prop: 'GWADL004', width: '150'},
                                        {label: '助记码', prop: 'GWADL005', width: '150'}
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWBS016 = data.GWAD002;
                                    vueData.form.GWADL004 = data.GWADL004+' '+data.GWAD002;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择省份',
                                area: ['600px', '465px']
                            }
                        });
                    },
                    openGwaol003:function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_gwao001',
                                    columnList: [
                                        {label: '产品系列编号', prop: 'GWAO001', width: '150'},
                                        {label: '产品系列名称', prop: 'GWAOL003', width: '150'},
                                        {label: '助记码', prop: 'GWAOL004', width: '150'},
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWBS017 = data.GWAO001;
                                    vueData.form.GWAOL003 = data.GWAOL003+' '+data.GWAO001;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择产品系列',
                                area: ['600px', '465px']
                            }
                        });
                    },
                    openGwbs003:function () {
                        if(vueData.form.GWBS017 == null || vueData.form.GWBS017 == ''){
                            app.showMessage("请先选择产品！");
                            return ;
                        }
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_gwam001',
                                    searchParam: {
                                        GWAM004: vueData.form.GWBS017
                                    },
                                    columnList: [
                                        {label: '产品编号', prop: 'GWAM001', width: '150'},
                                        {label: '产品名称', prop: 'GWAML003', width: '150'},
                                        {label: '规格', prop: 'GWAML004', width: '150'}
                                    ]
                                },
                                cb: function (data) {
                                    vueData.form.GWBS003 = data.GWAM001;
                                    vueData.form.GWAML003 = data.GWAML003;
                                    vueData.form.GWAML004 = data.GWAML004;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择产品',
                                area: ['600px', '465px']
                            }
                        });
                    },
                    openGwabl003:function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_gwab001',
                                    columnList: [
                                        {label: '单位', prop: 'GWAB001', width: '150'},
                                        {label: '说明', prop: 'GWABL003', width: '150'},
                                        {label: '助记码', prop: 'GWABL004', width: '150'}
                                    ]
                                },
                                cb: function (data) {
                                    vueData.form.GWBS004 = data.GWAB001;
                                    vueData.form.GWABL003 = data.GWABL003 + ' ' + data.GWAB001;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择单位',
                                area: ['600px', '465px']
                            }
                        });
                    },
                    openGwbs010:function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'q_sysuser_id',
                                    columnList: [
                                        {label: '业务员编号', prop: 'ID', width: '150'},
                                        {label: '业务员姓名', prop: 'NAME', width: '150'}
                                    ]
                                },
                                cb: function (data) {
                                    // vueData.form.GWBS010 = data.ACCOUNT;
                                    // 20191201 wenchuan.li换成存id字段
                                    vueData.form.GWBS010 = data.ID;
                                    vueData.form.GWBS010_NAME_ = data.ACCOUNT + ' ' + data.ID;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择业务人员',
                                area: ['600px', '470px']
                            }
                        });
                    },
                    openGwbs018:function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_sysorg_id',
                                    searchParam: {
                                        TYPE: 2
                                    },
                                    columnList: [
                                        { label: '公司名称', prop: 'NAME', width: '150'},
                                        { label: 'ID', prop: 'ID', width: '150'}
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWBS018 = data.ID;
                                    vueData.form.GWBS018_NAME_ = data.NAME + ' ' + data.ID;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择大区/分公司',
                                area: ['600px', '465px']
                            }
                        });
                    }
                },
                watch: {
                    'form.GWBS002':function () {
                        if(vueData.form.GWBS002 == ''){
                            vueData.form.GWAKL003 = '';
                            vueData.form.GWBS001 = '';
                            vueData.form.GWBGL003 = '';
                        }
                    },
                    'form.GWBS009':function () {
                        if(vueData.form.GWBS009 == ''){
                            vueData.form.GWAKL003_ = '';
                        }
                    },
                    'form.GWBS001':function () {
                        if(vueData.form.GWBS001 == ''){
                            vueData.form.GWBGL003 = '';
                        }
                    },
                    'form.GWAGL003':function () {
                        if(vueData.form.GWAGL003 == ''){
                            vueData.form.GWBS015 = '';
                        }
                    },
                    'form.GWADL004':function () {
                        if(vueData.form.GWADL004 == ''){
                            vueData.form.GWBS016 = '';
                        }
                    },
                    'form.GWAOL003':function () {
                        if(vueData.form.GWAOL003 == ''){
                            vueData.form.GWBS017 = '';
                        }
                    },
                    'form.GWBS003':function () {
                        if(vueData.form.GWBS003 == ''){
                            vueData.form.GWAML003 = '';
                            vueData.form.GWAML004 = '';
                        }
                    },
                    'form.GWABL003':function () {
                        if(vueData.form.GWABL003 == ''){
                            vueData.form.GWBS004 = '';
                        }
                    },
                    'form.GWBS010_NAME_':function () {
                        if(vueData.form.GWBS010_NAME_ == ''){
                            vueData.form.GWBS010 = '';
                        }
                    },
                    'form.GWBS018_NAME_':function () {
                        if(vueData.form.GWBS018_NAME_ == ''){
                            vueData.form.GWBS018 = '';
                        }
                    }
                },
                created: function () {
                    self._setEleIsReady('gwat550_edit');
                }
            });
        },

        _lazy: function () {
            this._super();
        }
    });

    return new Gwat550Edit();

});